﻿using System.Threading;

namespace Nutilities.Threading
{
    public abstract class ThreadClass
    {
        protected bool Running { get; set; }
        private Thread _thread;

        public string Name { get; set; }

        public void Start()
        {
            Running = true;
            _thread = new Thread(Run) {Name = Name};
            _thread.Start();
        }

        public void Terminate()
        {
            Running = false;
        }

        public void Stop()
        {
            Terminate();
            _thread.Join();
        }

        public abstract void Run();
    }
}
